
package com.jf.cloud.biz.controller.platform;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.PhoneUtil;
import com.jf.cloud.biz.dto.NotifyLogDTO;
import com.jf.cloud.biz.service.NotifyLogService;
import com.jf.cloud.biz.vo.NotifyLogVO;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Objects;

/**
 *
 *
 * @author zz
 * @date 2021-05-14 09:35:32
 */
@RestController("platformNotifyLogController")
@RequestMapping("/p/notify_log")
@Tag(name = "消息日志")
public class NotifyLogController {

    @Autowired
    private NotifyLogService notifyLogService;
    @Value("${jfcloud.expose.operation.auth:}")
    private Boolean permission;

    @GetMapping("/page")
    @Operation(summary = "获取列表" , description = "分页获取列表")
    public ServerResponseEntity<PageVO<NotifyLogVO>> page(@Valid PageDTO pageDTO, @ParameterObject NotifyLogDTO notifyLogDTO) {
        PageVO<NotifyLogVO> notifyLogPage = notifyLogService.page(pageDTO,notifyLogDTO);

        if (BooleanUtil.isFalse(permission)){
            for (NotifyLogVO record : notifyLogPage.getList()) {
                if (Objects.nonNull(record.getUserMobile())) {
                    record.setUserMobile(PhoneUtil.hideBetween(record.getUserMobile()).toString());
                }
            }
        }
        return ServerResponseEntity.success(notifyLogPage);
    }
}
